<template>
  <div class="notice-list">
    <div class="content">
      <div class="crumbs">
        <nuxt-link to="/" class="item-a" v-if="shopId==0">{{$t('commonHead.home')}}</nuxt-link>
        <nuxt-link :to="`shopIndex?sid=${shopId}`" class="item-a" v-else>{{$t('freeShop.storeHome')}}</nuxt-link>
        <span class="arrow">></span>
        <span class="item-span">{{shopId==0 ? $t('lanhaiHeadlines') : $t('storeAnnouncement')}}</span>
      </div>
      <div class="list">
        <div class="item" v-for="item in noticeList" :key="item.id" @click="goNoticeDet(item.id)">
          <div class="tit">{{item.title}}</div>
          <div class="time">{{item.publishTime.substring(0,10)}}</div>
        </div>
      </div>
      <!-- 页码 -->
      <pagination v-model="current" :pages="pages" @changePage="getNoticeList"></pagination>
      <!-- /页码 -->
    </div>
  </div>
</template>

<script>

import Pagination from '~/components/pagination'

export default {
  components: { Pagination },
  data () {
    return {
      noticeList: [],  // 公告列表
      pages: 1, // 总页数
      current: this.$route.query.current || 1, // 当前页数
      shopId: this.$route.query.shopId || 0
    }
  },
  mounted () {
    this.getNoticeList(1)
  },
  methods: {

    // 获取公告列表
    getNoticeList (cur) {
      this.$axios.get('/shop/notice/noticeList/' + this.shopId, {
        params: {
          current: cur,  //当前页
          size: 7
        }
      }).then(({ data }) => {
        this.noticeList = data.records
        this.pages = data.pages
      })
    },

    // 去公告详情
    goNoticeDet (id) {
      this.$router.push({
        path: '/notice-detail',
        query: {
          id: id,
          shopId: this.shopId
        }
      })
    }

  },
}
</script>

<style scoped src='~/assets/css/notice-list.css'></style>
